package org.domain.sigerec.session;

import java.util.Arrays;
import java.util.List;

import org.domain.sigerec.entity.Navio;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityQuery;

@Name("navioList")
public class NavioList extends EntityQuery<Navio>{
	
	private static final long serialVersionUID = -268824361076176905L;

	private static final String[] RESTRICTIONS = { "lower(navio.nome) like concat(lower(#{navioList.navio.nome}),'%') ", "navio.numero = #{navioList.navio.numero}",};

	private Navio navio = new Navio();
	
	@Override
	public Integer getMaxResults() {
		return 25;
	}

	public Navio getNavio() {
		return navio;
	}

	@Override
	public List<String> getRestrictions() {
		return Arrays.asList(RESTRICTIONS);
	}

	private boolean pesquisou;

	public List<Navio> getNavios() {
		if (pesquisou || getFirstResult()!= null) {
			return getResultList();
		}
		return null;
	}

	public String pesquisar() {
		pesquisou = true;
		return null;
	}
	
	@Override
    public String getEjbql() 
    { 
        return "select navio from Navio navio";
    }
}
